<!DOCTYPE html>
<html>
<head><meta name="generator" content="Hexo 3.8.0">
    

    

    



    <meta charset="utf-8">
    
    
    
    
    <title>mpvue-自定义导航栏 | lafen | lafen&#39;s personal blog</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    
    <meta name="theme-color" content="#3F51B5">
    
    
    <meta name="keywords" content="mpvue">
    <meta name="description" content="前言​        需求千千万万，产品客户各一半。小程序生态越来越成熟，承载的业务占比也越来越重要，要实现的业务场景也越来越多，功能需求也是越来越复杂啦。 需求场景​        客户反映从模板消息进入小程序指定页面时，没有一个明显的按钮能够返回到主页面，苦逼的业务猿当然得解决这个问题啊，总不能让用户点击右上角胶囊的回到主页面，当然这种需求早已有了各式各样的解决办法，其中自定义导航栏就是其中比">
<meta name="keywords" content="mpvue">
<meta property="og:type" content="article">
<meta property="og:title" content="mpvue-自定义导航栏">
<meta property="og:url" content="https://lafen.gitee.io/2019/08/18/mpvue-自定义导航栏/mpvue-自定义导航栏/index.html">
<meta property="og:site_name" content="lafen">
<meta property="og:description" content="前言​        需求千千万万，产品客户各一半。小程序生态越来越成熟，承载的业务占比也越来越重要，要实现的业务场景也越来越多，功能需求也是越来越复杂啦。 需求场景​        客户反映从模板消息进入小程序指定页面时，没有一个明显的按钮能够返回到主页面，苦逼的业务猿当然得解决这个问题啊，总不能让用户点击右上角胶囊的回到主页面，当然这种需求早已有了各式各样的解决办法，其中自定义导航栏就是其中比">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="https://i.loli.net/2019/08/17/s68l9vuQi2PJ3gR.png">
<meta property="og:image" content="https://i.loli.net/2019/08/17/2VMvhRpxHkIi8qu.png">
<meta property="og:image" content="https://i.loli.net/2019/08/17/s68l9vuQi2PJ3gR.png">
<meta property="og:updated_time" content="2019-09-17T05:43:04.674Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="mpvue-自定义导航栏">
<meta name="twitter:description" content="前言​        需求千千万万，产品客户各一半。小程序生态越来越成熟，承载的业务占比也越来越重要，要实现的业务场景也越来越多，功能需求也是越来越复杂啦。 需求场景​        客户反映从模板消息进入小程序指定页面时，没有一个明显的按钮能够返回到主页面，苦逼的业务猿当然得解决这个问题啊，总不能让用户点击右上角胶囊的回到主页面，当然这种需求早已有了各式各样的解决办法，其中自定义导航栏就是其中比">
<meta name="twitter:image" content="https://i.loli.net/2019/08/17/s68l9vuQi2PJ3gR.png">
    
        <link rel="alternate" type="application/atom+xml" title="lafen" href="/atom.xml">
    
    <link rel="shortcut icon" href="/img/favicon.ico">
    <link rel="stylesheet" href="//unpkg.com/hexo-theme-material-indigo@latest/css/style.css">
    <script>window.lazyScripts=[]</script>

    <!-- custom head -->
    

</head>

<body>
    <div id="loading" class="active"></div>

    <aside id="menu" class="hide">
  <div class="inner flex-row-vertical">
    <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menu-off">
        <i class="icon icon-lg icon-close"></i>
    </a>
    <div class="brand-wrap" style="background-image:url(/img/brand.jpg)">
      <div class="brand">
        <a href="/" class="avatar waves-effect waves-circle waves-light">
          <img src="/img/avatar.jpg">
        </a>
        <hgroup class="introduce">
          <h5 class="nickname">lafen</h5>
          <a href="mailto:1031822863@qq.com" title="1031822863@qq.com" class="mail">1031822863@qq.com</a>
        </hgroup>
      </div>
    </div>
    <div class="scroll-wrap flex-col">
      <ul class="nav">
        
            <li class="waves-block waves-effect">
              <a href="/">
                <i class="icon icon-lg icon-home"></i>
                home
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/archives">
                <i class="icon icon-lg icon-archives"></i>
                Archives
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/tags">
                <i class="icon icon-lg icon-tags"></i>
                Tags
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/categories">
                <i class="icon icon-lg icon-th-list"></i>
                Categories
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://github.com/zhongxiaotian" target="_blank">
                <i class="icon icon-lg icon-github"></i>
                Github
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="http://www.weibo.com/" target="_blank">
                <i class="icon icon-lg icon-weibo"></i>
                Weibo
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://gitee.com/lafen" target="_blank">
                <i class="icon icon-lg icon-link"></i>
                Gitee
              </a>
            </li>
        
      </ul>
    </div>
  </div>
</aside>

    <main id="main">
        <header class="top-header" id="header">
    <div class="flex-row">
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light on" id="menu-toggle">
          <i class="icon icon-lg icon-navicon"></i>
        </a>
        <div class="flex-col header-title ellipsis">mpvue-自定义导航栏</div>
        
        <div class="search-wrap" id="search-wrap">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="back">
                <i class="icon icon-lg icon-chevron-left"></i>
            </a>
            <input type="text" id="key" class="search-input" autocomplete="off" placeholder="输入感兴趣的关键字">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="search">
                <i class="icon icon-lg icon-search"></i>
            </a>
        </div>
        
        
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menuShare">
            <i class="icon icon-lg icon-share-alt"></i>
        </a>
        
    </div>
</header>
<header class="content-header post-header">

    <div class="container fade-scale">
        <h1 class="title">mpvue-自定义导航栏</h1>
        <h5 class="subtitle">
            
                <time datetime="2019-08-17T16:49:40.000Z" itemprop="datePublished" class="page-time">
  2019-08-18
</time>


	<ul class="article-category-list"><li class="article-category-list-item"><a class="article-category-list-link" href="/categories/mpvue/">mpvue</a></li></ul>

            
        </h5>
    </div>

    


</header>


<div class="container body-wrap">
    
    <aside class="post-widget">
        <nav class="post-toc-wrap post-toc-shrink" id="post-toc">
            <h4>TOC</h4>
            <ol class="post-toc"><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#前言"><span class="post-toc-number">1.</span> <span class="post-toc-text">前言</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#需求场景"><span class="post-toc-number">2.</span> <span class="post-toc-text">需求场景</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#文档"><span class="post-toc-number">3.</span> <span class="post-toc-text">文档</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#思路"><span class="post-toc-number">4.</span> <span class="post-toc-text">思路</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#代码"><span class="post-toc-number">5.</span> <span class="post-toc-text">代码</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#使用"><span class="post-toc-number">6.</span> <span class="post-toc-text">使用</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#最后"><span class="post-toc-number">7.</span> <span class="post-toc-text">最后</span></a></li></ol>
        </nav>
    </aside>


<article id="post-mpvue-自定义导航栏/mpvue-自定义导航栏" class="post-article article-type-post fade" itemprop="blogPost">

    <div class="post-card">
        <h1 class="post-card-title">mpvue-自定义导航栏</h1>
        <div class="post-meta">
            <time class="post-time" title="2019-08-18 00:49:40" datetime="2019-08-17T16:49:40.000Z" itemprop="datePublished">2019-08-18</time>

            
	<ul class="article-category-list"><li class="article-category-list-item"><a class="article-category-list-link" href="/categories/mpvue/">mpvue</a></li></ul>



            
<span id="busuanzi_container_page_pv" title="文章总阅读量" style="display:none">
    <i class="icon icon-eye icon-pr"></i><span id="busuanzi_value_page_pv"></span>
</span>


        </div>
        <div class="post-content" id="post-content" itemprop="postContent">
            <h3 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h3><p>​        需求千千万万，产品客户各一半。小程序生态越来越成熟，承载的业务占比也越来越重要，要实现的业务场景也越来越多，功能需求也是越来越复杂啦。</p>
<h3 id="需求场景"><a href="#需求场景" class="headerlink" title="需求场景"></a>需求场景</h3><p>​        客户反映从模板消息进入小程序指定页面时，没有一个明显的按钮能够返回到主页面，苦逼的业务猿当然得解决这个问题啊，总不能让用户点击右上角胶囊的回到主页面，当然这种需求早已有了各式各样的解决办法，其中<strong>自定义导航栏</strong>就是其中比较合适的啦，以下就是在小程序中自定义导航栏的效果。</p>
<figure class="image-bubble">
                <div class="img-lightbox">
                    <div class="overlay"></div>
                    <img src="https://i.loli.net/2019/08/17/s68l9vuQi2PJ3gR.png" alt="1566013673410.png" title="">
                </div>
                <div class="image-caption">1566013673410.png</div>
            </figure>
<h3 id="文档"><a href="#文档" class="headerlink" title="文档"></a>文档</h3><p>​        小程序从微信<code>7.0.0</code>开始就支持在单个页面<a href="https://developers.weixin.qq.com/miniprogram/dev/reference/configuration/page.html" target="_blank" rel="noopener">自定义导航栏</a>，而不必在全局中设置</p>
<figure class="image-bubble">
                <div class="img-lightbox">
                    <div class="overlay"></div>
                    <img src="https://i.loli.net/2019/08/17/2VMvhRpxHkIi8qu.png" alt="1566013059762.png" title="">
                </div>
                <div class="image-caption">1566013059762.png</div>
            </figure>
<h3 id="思路"><a href="#思路" class="headerlink" title="思路"></a>思路</h3><p>以下是实现的思路</p>
<ol>
<li><p><strong>页面配置</strong>，页面<code>main.json</code>中配置<code>navigatorStyle:custom</code>开启自定义导航栏设置</p>
</li>
<li><p><strong>全局组件</strong>，将自定义导航栏放到全局组件下，以便其他页面复用</p>
</li>
<li><p><strong>层级问题</strong>，为保证导航栏拥有较高的层级，不被其他组件覆盖，使用微信小程序的<code>cover-view</code>和<code>cover-image</code>进行布局，实际上<code>cover-view</code>和<code>cover-image</code>也是原生组件，与其他原生组件（比如<code>canvas</code>）也存在层级问题，故使用<code>postion:fixed</code>将其固定在页面顶部的同时，将需要其层级<code>z-index</code>设置得比页面的原生组件高</p>
</li>
<li><p><strong>导航栏高度</strong>，各式各样的全面屏浏览屏都要适配到，就需要动态计算导航栏的高度，其中可进行如下计算</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 导航栏高度 = 状态栏高度 + 标题栏高度</span></span><br><span class="line">customBarHeight = statusBarHeight + titleBarHeight</span><br></pre></td></tr></table></figure>
<ul>
<li><p><code>statusBarHeight</code>可通过<code>wx.getSystemInfoSync()</code>获取，单位是<code>px</code></p>
</li>
<li><p><code>titleBarHeight</code>在<code>iOS</code>和<code>Android</code>中表现不一致，具体可以查看<a href="https://developers.weixin.qq.com/miniprogram/design/#%E5%9B%BE%E6%A0%87" target="_blank" rel="noopener">微信设计文档</a>，大致就是<code>iOS</code>下的<code>titleBarHeight=44px</code>，而<code>Android</code>下的<code>titleBarHeight=48px</code></p>
</li>
<li><p>区分<code>iOS</code>与<code>Android</code>系统也可以通过<code>wx.getSystemInfoSync()</code>的<code>system</code>字段获取</p>
</li>
</ul>
<p>即有以下代码</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 适配不同屏幕 customBarHeight = 状态栏statusBarHeight + 标题栏titleBarHeight (px)</span></span><br><span class="line"><span class="comment">// 状态栏 statusBarHeight</span></span><br><span class="line"><span class="comment">// 标题栏 titleBarHeight ： android:48px  iOS:44px</span></span><br><span class="line"><span class="keyword">const</span> systemInfo = wx.getSystemInfoSync()</span><br><span class="line"><span class="keyword">const</span> &#123; statusBarHeight, system &#125; = systemInfo</span><br><span class="line"><span class="keyword">let</span> titleBarHeight = (system.indexOf(<span class="string">'iOS'</span>) !== <span class="number">-1</span>) ? <span class="number">44</span> : <span class="number">48</span></span><br><span class="line"><span class="keyword">this</span>.customBarHeight = statusBarHeight + titleBarHeight</span><br></pre></td></tr></table></figure>
</li>
<li><p><strong>单位</strong>，使用<code>px</code></p>
</li>
</ol>
<h3 id="代码"><a href="#代码" class="headerlink" title="代码"></a>代码</h3><p>​        以上基本考虑了一些遇到的问题与方法思路，以下就是实现的代码了</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br></pre></td><td class="code"><pre><span class="line">&lt;template&gt;</span><br><span class="line">  &lt;cover-view class=&quot;custom-navigator&quot; :class=&quot;customStyle&quot; :style=&quot;&apos;height:&apos;+customBarHeight+&apos;px;&apos;&quot;&gt;</span><br><span class="line">    &lt;cover-view class=&quot;wrap&quot;&gt;</span><br><span class="line">      &lt;cover-view class=&quot;nav-left&quot; :class=&quot;menuStyle&quot;&gt;</span><br><span class="line">        &lt;cover-image v-if=&quot;back&quot; class=&quot;nav-icon back&quot; src=&quot;/static/images/back.png&quot; @click=&quot;handleBack&quot;&gt;&lt;/cover-image&gt;</span><br><span class="line">        &lt;cover-view v-if=&quot;showSpan&quot; class=&quot;span&quot;&gt;&lt;/cover-view&gt;</span><br><span class="line">        &lt;cover-image v-if=&quot;home&quot; class=&quot;nav-icon home&quot; src=&quot;/static/images/home.png&quot; @click=&quot;handleHome&quot;&gt;&lt;/cover-image&gt;</span><br><span class="line">      &lt;/cover-view&gt;</span><br><span class="line">      &lt;cover-view class=&quot;title&quot;&gt;&#123;&#123; title &#125;&#125;&lt;/cover-view&gt;</span><br><span class="line">    &lt;/cover-view&gt;</span><br><span class="line">  &lt;/cover-view&gt;</span><br><span class="line">&lt;/template&gt;</span><br><span class="line">&lt;script&gt;</span><br><span class="line">export default &#123;</span><br><span class="line">  name: &apos;CustomNavigator&apos;,</span><br><span class="line">  props: &#123;</span><br><span class="line">    back: &#123;</span><br><span class="line">      type: Boolean,</span><br><span class="line">      default: true</span><br><span class="line">    &#125;,</span><br><span class="line">    home: &#123;</span><br><span class="line">      type: Boolean,</span><br><span class="line">      default: true</span><br><span class="line">    &#125;,</span><br><span class="line">    title: &#123;</span><br><span class="line">      type: String,</span><br><span class="line">      default: &apos;自定义标题栏&apos;</span><br><span class="line">    &#125;,</span><br><span class="line">    customStyle: &#123;</span><br><span class="line">      type: String,</span><br><span class="line">      default: &apos;dark&apos;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;,</span><br><span class="line">  computed: &#123;</span><br><span class="line">    showSpan() &#123;</span><br><span class="line">      return this.back &amp;&amp; this.home</span><br><span class="line">    &#125;,</span><br><span class="line">    menuStyle() &#123;</span><br><span class="line">      if (this.back &amp;&amp; this.home) return &apos;both&apos;</span><br><span class="line">      else if (this.back || this.home) return &apos;single&apos;</span><br><span class="line">      else return &apos;none&apos;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;,</span><br><span class="line">  data () &#123;</span><br><span class="line">    return &#123;</span><br><span class="line">      customBarHeight: 0</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;,</span><br><span class="line">  onLoad() &#123;</span><br><span class="line">    // 适配不同屏幕 customBarHeight = 状态栏statusBarHeight + 标题栏titleBarHeight (px)</span><br><span class="line">    // 状态栏 statusBarHeight</span><br><span class="line">    // 标题栏 titleBarHeight ： android:48px  iOS:44px</span><br><span class="line">    const systemInfo = wx.getSystemInfoSync()</span><br><span class="line">    const &#123; statusBarHeight, system &#125; = systemInfo</span><br><span class="line">    let titleBarHeight = (system.indexOf(&apos;iOS&apos;) !== -1) ? 44 : 48</span><br><span class="line">    this.customBarHeight = statusBarHeight + titleBarHeight</span><br><span class="line">    wx.setStorageSync(&apos;SystemInfo&apos;, systemInfo)</span><br><span class="line">  &#125;,</span><br><span class="line">  methods: &#123;</span><br><span class="line">    handleHome() &#123;</span><br><span class="line">      wx.switchTab(&#123; url: &apos;/pages/index/main&apos; &#125;)</span><br><span class="line">    &#125;,</span><br><span class="line">    handleBack() &#123;</span><br><span class="line">      const pages = getCurrentPages()</span><br><span class="line">      if(pages.length &gt; 1) &#123;</span><br><span class="line">        wx.navigateBack(&#123;</span><br><span class="line">          delta: 1 //返回的页面数，如果 delta 大于现有页面数，则返回到首页,</span><br><span class="line">        &#125;)</span><br><span class="line">      &#125; else &#123;</span><br><span class="line">        wx.switchTab(&#123; url: &apos;/pages/index/main&apos; &#125;);</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line">&lt;/script&gt;</span><br><span class="line">&lt;style lang=&quot;scss&quot; scoped&gt;</span><br><span class="line">.custom-navigator &#123;</span><br><span class="line">  position: fixed;</span><br><span class="line">  top: 0;</span><br><span class="line">  left: 0;</span><br><span class="line">  right: 0;</span><br><span class="line">  width: 100%;</span><br><span class="line">  background-color: #17a1e5;</span><br><span class="line">  color: #fff;</span><br><span class="line">  font-size: 32rpx;</span><br><span class="line">  .wrap &#123;</span><br><span class="line">    position: absolute;</span><br><span class="line">    bottom: 7px;</span><br><span class="line">    width: 94%;</span><br><span class="line">    padding: 0 10px;</span><br><span class="line">    .nav-left &#123;</span><br><span class="line">      box-sizing: border-box;</span><br><span class="line">      padding: 4px 0;</span><br><span class="line">      display: flex;</span><br><span class="line">      justify-content: space-around;</span><br><span class="line">      align-items: center;</span><br><span class="line">      width: 85px;</span><br><span class="line">      height: 28px;</span><br><span class="line">      // background-color: rgba(0, 0, 0, 0);</span><br><span class="line">      background-color: rgba(0, 0, 0, 0.15);</span><br><span class="line">      border-radius: 15px;</span><br><span class="line">      .nav-icon &#123;</span><br><span class="line">        width: 20px;</span><br><span class="line">        height: 20px;</span><br><span class="line">        padding: 0 8px;</span><br><span class="line">      &#125;</span><br><span class="line">      .span &#123;</span><br><span class="line">        display: block;</span><br><span class="line">        position: relative;</span><br><span class="line">        width: 1rpx;</span><br><span class="line">        height: 16px;</span><br><span class="line">        margin: 3px 0;</span><br><span class="line">        background-color: rgba(255, 255, 255, 0.6);</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    .title &#123;</span><br><span class="line">      position: absolute;</span><br><span class="line">      bottom: 0;</span><br><span class="line">      left: 50%;</span><br><span class="line">      transform: translateX(-50%);</span><br><span class="line">      height: 28px;</span><br><span class="line">      line-height: 28px;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">// 胶囊宽度</span><br><span class="line">.both &#123;</span><br><span class="line">  width: 85px !important;</span><br><span class="line">&#125;</span><br><span class="line">.single &#123;</span><br><span class="line">  width: 42px !important;</span><br><span class="line">&#125;</span><br><span class="line">.none &#123;</span><br><span class="line">  width: 85px !important;</span><br><span class="line">  background-color: rgba(0,0,0,0) !important;</span><br><span class="line">&#125;</span><br><span class="line">// 背景色调定义</span><br><span class="line">.light &#123;</span><br><span class="line">  background-color: #fff;</span><br><span class="line">  color: #333;</span><br><span class="line">&#125;</span><br><span class="line">.dark &#123;</span><br><span class="line">  background-color: #17a1e5;</span><br><span class="line">  color: #fff;</span><br><span class="line">&#125;</span><br><span class="line">&lt;/style&gt;</span><br></pre></td></tr></table></figure>
<h3 id="使用"><a href="#使用" class="headerlink" title="使用"></a>使用</h3><p>​        页面引入注册组件后使用，效果如图</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">&lt;CustomNavigator</span><br><span class="line">    :back=&quot;true&quot;</span><br><span class="line">    :home=&quot;true&quot;</span><br><span class="line">    title=&quot;自定义导航栏&quot;</span><br><span class="line">    customStyle=&quot;dark&quot; /&gt;</span><br></pre></td></tr></table></figure>
<figure class="image-bubble">
                <div class="img-lightbox">
                    <div class="overlay"></div>
                    <img src="https://i.loli.net/2019/08/17/s68l9vuQi2PJ3gR.png" alt="1566013673410.png" title="">
                </div>
                <div class="image-caption">1566013673410.png</div>
            </figure>
<h3 id="最后"><a href="#最后" class="headerlink" title="最后"></a>最后</h3><p>​        实现并不难，掌握思路最重要，另外自己可以加上不同的参数去控制显示也可</p>

        </div>

        <blockquote class="post-copyright">
    
    <div class="content">
        
<span class="post-time">
    最后更新时间：<time datetime="2019-09-17T05:43:04.674Z" itemprop="dateUpdated">2019-09-17 13:43:04</time>
</span><br>


        
        关于学习类文章网上已经有非常多，而此处文章都是我在学习过程中整理摘录的笔记，参考文章可以点击文末的参考链接进行查阅
        
    </div>
    
    <footer>
        <a href="https://lafen.gitee.io">
            <img src="/img/avatar.jpg" alt="lafen">
            lafen
        </a>
    </footer>
</blockquote>

        
<div class="page-reward">
    <a id="rewardBtn" href="javascript:;" class="page-reward-btn waves-effect waves-circle waves-light">赏</a>
</div>



        <div class="post-footer">
            
	<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/mpvue/">mpvue</a></li></ul>


            
<div class="page-share-wrap">
    

<div class="page-share" id="pageShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=https://lafen.gitee.io/2019/08/18/mpvue-自定义导航栏/mpvue-自定义导航栏/&title=《mpvue-自定义导航栏》 — lafen&pic=https://lafen.gitee.io/img/avatar.jpg" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=https://lafen.gitee.io/2019/08/18/mpvue-自定义导航栏/mpvue-自定义导航栏/&title=《mpvue-自定义导航栏》 — lafen&source=lafen's personal blog" data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=https://lafen.gitee.io/2019/08/18/mpvue-自定义导航栏/mpvue-自定义导航栏/" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《mpvue-自定义导航栏》 — lafen&url=https://lafen.gitee.io/2019/08/18/mpvue-自定义导航栏/mpvue-自定义导航栏/&via=https://lafen.gitee.io" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=https://lafen.gitee.io/2019/08/18/mpvue-自定义导航栏/mpvue-自定义导航栏/" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>



    <a href="javascript:;" id="shareFab" class="page-share-fab waves-effect waves-circle">
        <i class="icon icon-share-alt icon-lg"></i>
    </a>
</div>



        </div>
    </div>

    
<nav class="post-nav flex-row flex-justify-between">
  
    <div class="waves-block waves-effect prev">
      <a href="/2019/08/30/mpvue-使用flyio发起request请求/mpvue-使用flyio发起request请求/" id="post-prev" class="post-nav-link">
        <div class="tips"><i class="icon icon-angle-left icon-lg icon-pr"></i> Prev</div>
        <h4 class="title">mpvue-使用flyio发起request请求</h4>
      </a>
    </div>
  

  
    <div class="waves-block waves-effect next">
      <a href="/2019/01/22/js-浅拷贝与深拷贝/js-浅拷贝与深拷贝/" id="post-next" class="post-nav-link">
        <div class="tips">Next <i class="icon icon-angle-right icon-lg icon-pl"></i></div>
        <h4 class="title">浅拷贝与深拷贝</h4>
      </a>
    </div>
  
</nav>



    




















</article>

<div id="reward" class="page-modal reward-lay">
    <a class="close" href="javascript:;"><i class="icon icon-close"></i></a>
    <h3 class="reward-title">
        <i class="icon icon-quote-left"></i>
        打笔巨款？~
        <i class="icon icon-quote-right"></i>
    </h3>
    <div class="reward-content">
        
        <div class="reward-code">
            <img id="rewardCode" src="/img/wechat.jpg" alt="打赏二维码">
        </div>
        
        <label class="reward-toggle">
            <input id="rewardToggle" type="checkbox" class="reward-toggle-check" data-wechat="/img/wechat.jpg" data-alipay="/img/alipay.jpg">
            <div class="reward-toggle-ctrol">
                <span class="reward-toggle-item wechat">微信</span>
                <span class="reward-toggle-label"></span>
                <span class="reward-toggle-item alipay">支付宝</span>
            </div>
        </label>
        
    </div>
</div>



</div>

        <footer class="footer">
    <div class="top">
        
<p>
    <span id="busuanzi_container_site_uv" style="display:none">
        站点总访客数：<span id="busuanzi_value_site_uv"></span>
    </span>
    <span id="busuanzi_container_site_pv" style="display:none">
        站点总访问量：<span id="busuanzi_value_site_pv"></span>
    </span>
</p>


        <p>
            
                <span><a href="/atom.xml" target="_blank" class="rss" title="rss"><i class="icon icon-lg icon-rss"></i></a></span>
            
            <span>博客内容遵循 <a rel="license" href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh">知识共享 署名 - 非商业性 - 相同方式共享 4.0 国际协议</a></span>
        </p>
    </div>
    <div class="bottom">
        <p><span>lafen &copy; 2019 - 2020</span>
            <span>
                
                Power by <a href="http://hexo.io/" target="_blank">Hexo</a> Theme <a href="https://github.com/yscoder/hexo-theme-indigo" target="_blank">indigo</a>
            </span>
        </p>
    </div>
</footer>

    </main>
    <div class="mask" id="mask"></div>
<a href="javascript:;" id="gotop" class="waves-effect waves-circle waves-light"><span class="icon icon-lg icon-chevron-up"></span></a>



<div class="global-share" id="globalShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=https://lafen.gitee.io/2019/08/18/mpvue-自定义导航栏/mpvue-自定义导航栏/&title=《mpvue-自定义导航栏》 — lafen&pic=https://lafen.gitee.io/img/avatar.jpg" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=https://lafen.gitee.io/2019/08/18/mpvue-自定义导航栏/mpvue-自定义导航栏/&title=《mpvue-自定义导航栏》 — lafen&source=lafen's personal blog" data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=https://lafen.gitee.io/2019/08/18/mpvue-自定义导航栏/mpvue-自定义导航栏/" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《mpvue-自定义导航栏》 — lafen&url=https://lafen.gitee.io/2019/08/18/mpvue-自定义导航栏/mpvue-自定义导航栏/&via=https://lafen.gitee.io" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=https://lafen.gitee.io/2019/08/18/mpvue-自定义导航栏/mpvue-自定义导航栏/" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>


<div class="page-modal wx-share" id="wxShare">
    <a class="close" href="javascript:;"><i class="icon icon-close"></i></a>
    <p>扫一扫，分享到微信</p>
    <img src="" alt="微信分享二维码">
</div>




    <script src="//cdn.bootcss.com/node-waves/0.7.4/waves.min.js"></script>
<script>
var BLOG = { ROOT: '/', SHARE: true, REWARD: true };


</script>

<script src="//unpkg.com/hexo-theme-material-indigo@latest/js/main.min.js"></script>


<div class="search-panel" id="search-panel">
    <ul class="search-result" id="search-result"></ul>
</div>
<template id="search-tpl">
<li class="item">
    <a href="{path}" class="waves-block waves-effect">
        <div class="title ellipsis" title="{title}">{title}</div>
        <div class="flex-row flex-middle">
            <div class="tags ellipsis">
                {tags}
            </div>
            <time class="flex-col time">{date}</time>
        </div>
    </a>
</li>
</template>

<script src="//unpkg.com/hexo-theme-material-indigo@latest/js/search.min.js" async></script>






<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>



<script>
(function() {
    var OriginTitile = document.title, titleTime;
    document.addEventListener('visibilitychange', function() {
        if (document.hidden) {
            document.title = '死鬼去哪里了！';
            clearTimeout(titleTime);
        } else {
            document.title = '(つェ⊂)咦!又好了!';
            titleTime = setTimeout(function() {
                document.title = OriginTitile;
            },2000);
        }
    });
})();
</script>



<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"scale":1,"jsonPath":"/live2dw/assets/shizuku.model.json"},"display":{"positon":"right","width":150,"height":300},"mobile":{"show":true,"scale":0.8},"react":{"opacity":0.8,"opacityDefault":0.8,"opacityOnHover":0.6},"log":false});</script></body>
</html>
